package com.todaynews.utils;

import android.content.Context;
import android.content.SharedPreferences;
import com.todaynews.AppDroid;

public class PreUtils {

    public static final String CONFIG_FILE_NAME = "config";

    private final static PreUtils instance = new PreUtils();

    /**
     * 单例对象实例
     */
    public static PreUtils getInstance(){
        return instance;
    }

    public void putBoolean(String key, boolean value){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        sp.edit().putBoolean(key,value).commit();
    }

    public boolean getBoolean(String key, boolean defValue){
        SharedPreferences sp =AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(key,defValue);
    }

    public void putString(String key, String value){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        sp.edit().putString(key,value).commit();
    }

    public String getString(String key, String defValue){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getString(key,defValue);
    }

    public void putInt(String key, int value){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        sp.edit().putInt(key,value).commit();
    }

    public int getInt(String key, int defValue){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getInt(key,defValue);
    }

    public void putLong(String key, long value){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        sp.edit().putLong(key,value).commit();
    }

    public long getLong(String key, long defValue){
        SharedPreferences sp = AppDroid.getInstance().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        return sp.getLong(key,defValue);
    }

}
